public class demo03 {
    //动态规划（背包）
    public static void main(String[] args) {
        int[] weight={0,2,3,4,5};
        int[] values={0,3,4,5,8};
        int[][] arr=new int[5][9];
        int max=0;
        for (int i = 1; i < 5 ; i++) {
            for (int j = 1; j < 9; j++) {
                if (weight[i]>j){
                    arr[i][j]=arr[i-1][j];
                }else {
                    arr[i][j]=Math.max(arr[i-1][j],arr[i-1][j-weight[i]]+values[i]);
                }
                if(max<arr[i][j]){
                    max=arr[i][j];
                }
            }
        }
        System.out.println(max);
    }
}
